 
 	<?php
		function set_val($obj, $val, $return='echo')
		{
			if(isset($obj))
				if(isset($obj->$val))
					if($return=='echo')
						echo($obj->$val);
					else
						return $obj->$val;
		}
	?>
 
				<div><br>
					<form id="form" class="block-content form" action="<?php echo site_url('admin/role/save_role_permission')?>" method="post">
						<input type="hidden" id="id" name="id" value="<?php if(isset($id)) echo $id;?>" />
						
						<div class="_100">
							<p><label for="role_name">Role/Group Name</label>
							<input id="role_name" name="role_name" class="required" type="text" value="<?php set_val($role,'role_name')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="login_destination">Login Destination</label>
							<input id="login_destination" name="login_destination" class="" type="text" value="<?php set_val($role,'login_destination')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="default">Default Role?</label>
							<select id="default" name="default">
								<option value="0">No</option>
								<option value="1">Yes</option>
							</select>
						</div>
						
						<div class="_100">
							<p><label for="description">Role/Group Description</label>
							<textarea id="description" name="description" class="required"><?php set_val($role,'description')?></textarea></p>
						</div>
						
						

						<div class="clear"></div>
						<div class="block-actions">
							<ul class="actions-left">
								<li><a class="button red" id="reset-validate-form" href="javascript:void(0);">Reset</a></li>
							</ul>
							<ul class="actions-right">
								<li><input type="submit" class="button" value="Save!"></li>
							</ul>
						</div>
					</form>

				</div>
				
				
	<script type="text/javascript">
						
		
	$().ready(function() {
		
		/** Submit Form **/
		$("#form").validate({
				rules:{},
				messages: {},
				submitHandler: function(form) {
				   //submit
				$.post("<?php echo site_url('admin/role/save_role')?>", $("#form").serialize(),
					function(data){
						if(data){
							
							newdata = $.parseJSON(data);
							
							if(newdata.error){
								Gtheme = 'error';
								
								$.each(newdata.msg, function(index) {
									$.jGrowl(newdata.msg[index], { theme: Gtheme,position:'center'  });
								});

							}
							else{
								Gtheme = 'saved';
								$.jGrowl(newdata.msg, { theme: Gtheme,position:'center'  });
								
								temp_id 		 = $("#id").val();
								temp_name 		 = $("#role_name").val();
								temp_description = $("#description").val();
								
								//clear the folrm
									$("#id").val('');
									$(":input").not(":button, :submit, :reset, :hidden").each(function () {
										this.value = '';
									});
								if(newdata.id > 0){
									temp_id = newdata.id;
									load_role(temp_id,temp_name);
									var tbl_row = '';
									tbl_row+='<tr id="row'+temp_id+'">';
									tbl_row+='<td class="middle"><a href="javascript:;" title="'+temp_name+'" onClick="load_role('+temp_id+',this.title)">'+temp_name+'</a></td>';
									tbl_row+='<td class="middle"><input id="checkbox_'+temp_id+'" type="checkbox" checked="checked" title="'+temp_name+'" onClick="enable_flags('+temp_id+')" /></td>';
									tbl_row+='<td>'+temp_description+'</td>';
									tbl_row+='<td class="middle"><a href="javascript:;" onClick="flag('+temp_id+')"><img src="<?php echo $this->config->item('images')?>/icons/packs/fugue/16x16/flag.png" alt="Add Flag to '+temp_name+'" title="Add Flag to '+temp_name+'" /></a></td>';
									tbl_row+='<td class="middle"><a onClick="load_form('+temp_id+')" href="javascript:;"><img src="<?php echo $this->config->item('images')?>/icons/packs/fugue/16x16/pencil.png" alt="Edit '+temp_name+'" title="Edit '+temp_name+'" /></a></td>';
									tbl_row+='<td class="middle"><a href="'+temp_id+'"><img src="<?php echo $this->config->item('images')?>/icons/packs/fugue/16x16/slash.png" alt="Delete '+temp_name+'" title="Delete '+temp_name+'" /></a></td>';
									tbl_row+='</tr>';
									$('#role_table').append(tbl_row);
									$('#row'+temp_id).effect("highlight", {}, 3000);
								}
								else{
									load_role(temp_id,temp_name);
								}
							}

						}
						else{
							$.jGrowl("Error!", { theme: 'error' });
						}
					});
				}
			});
		/** End Submit Form **/
		
		});
		
		
    </script>

